
#include "PerformerInfo.h"
#include "PipelineTaskInfo.h"

#ifdef TTG_PL_VISUALIZER

using namespace ttg::extras;
using namespace ttg_internal;
using namespace ttg_internal::pipeline;

//---------------------
//--- PerformerInfo ---
//---------------------

void PerformerInfo::addTaskInfo(PipelineTaskInfo info)
{
	locker.enter();
	tasks.push_back(info);
	locker.leave();
}

std::vector<PipelineTaskInfo> PerformerInfo::getTaskInfo()
{
	std::vector<PipelineTaskInfo> res;
	locker.enter();
	res = tasks;
	locker.leave();
	return res;
}

void PerformerInfo::clear()
{
	locker.enter();
	tasks.clear();
	locker.leave();
}

void PerformerInfo::store(XMLTree &xml)
{
	xml.addSectionAndOpen("Performer");
	xml.addIntAttribute("ID", (int)getID());
	for (size_t i = 0; i < tasks.size(); i++)
		tasks[i].store(xml);
	xml.closeSection();
}

PerformerInfo *PerformerInfo::create(XMLTree &xml)
{
	int ID;
	if (!xml.getIntAttribute("ID", ID))
		throw ttg::Error(ttg::Error::FATAL, "PerformerInfo", "create",
						 "Cannot find \"ID\" attribute");
	PerformerInfo *res = new PerformerInfo(ID);
	xml.resetIterators();
	while (xml.openNextSection())
	{
		res->getTaskInfo().push_back(PipelineTaskInfo::create(xml.getSubXMLTree()));
		xml.closeSection();
	}
	return res;
}

#endif
